/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2021-2021.
 * Description: introduce ppc32 removing dcbz command
 * Author: Wanming Hu
 * Create: 2021-09-06
 */

#include <linux/printk.h>
#include <asm/code-patching.h>
#include <linux/rtos/remove_dcbz.h>

static bool remove_dcbz_enabled = true;

static int __init setup_use_dcbz(char *str)
{
	// to use dcbz branch, patch following function address to a nop instruction
	patch_instruction_site(&patch__arch_clear_user_nodcbz, ppc_inst(PPC_INST_NOP));
	patch_instruction_site(&patch__copy_page_nodcbz, ppc_inst(PPC_INST_NOP));
	patch_instruction_site(&patch__copy_tofrom_user_nodcbz, ppc_inst(PPC_INST_NOP));
	patch_instruction_site(&patch__csum_partial_copy_generic_nodcbz, ppc_inst(PPC_INST_NOP));

	remove_dcbz_enabled = false;
	pr_info("dcbz: kernel will NOT remove dcbz command.\n");

	return 0;
}

bool is_removing_dcbz(void)
{
	return remove_dcbz_enabled;
}
EXPORT_SYMBOL(is_removing_dcbz);

early_param("use_dcbz", setup_use_dcbz);
